package com.sky.entity;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.lang.reflect.Method;
import java.time.LocalDateTime;

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class Employee implements Serializable {

    private static final long serialVersionUID = 1L;

    private Long id;

    private String username;

    private String name;

    private String password;

    private String phone;

    private String sex;

    private String idNumber;

    private Integer status;

    //@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime createTime;

    //@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime updateTime;

    private Long createUser;

    private Long updateUser;

    public static void main(String[] args) throws Exception {
        //%03d 3:位数，0位数不足时补0，%d数字
        // 字符串格式化输出
        //System.out.println(String.format("employee%04d",222));
        Employee employee = new Employee();

        // 获取这个类下的所有的方法
        Method[] declaredMethods = employee.getClass().getDeclaredMethods();
        for (Method method : declaredMethods) {
            System.out.println(method.getName());
        }


        Method setCreateTime = employee.getClass()
            // 获取setCreateTime方法,方法是有一个参数，参数的类型LocalDateTime
            .getDeclaredMethod("setCreateTime", LocalDateTime.class);
        // 获取当前系统时间
        LocalDateTime now = LocalDateTime.now();
        // 调用方法employee.setCreateTime(now);
        setCreateTime.invoke(employee,now);
        System.out.println(employee);

        //调用getCreateTime()方法
        Method getCreateTime = employee.getClass()
            // 获取getCreateTime方法
            .getDeclaredMethod("getCreateTime");
        Object result = getCreateTime.invoke(employee, null);
        System.out.println(result);

        //Field @Autowired暴力反射 field.setAccessable(true)
    }
}
